<template>
  <div>
    <el-form ref="form" :model="OwnerPo" label-width="80px">
      <el-row>
        <el-col :span="13">
          <el-form-item label="业主名称">
            <el-input v-model="OwnerPo.name" placeholder="(必填)业主名称"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="OwnerPo.sex" placeholder="请选择性别">
              <el-option label="男" :value="1" ></el-option>
              <el-option label="女" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄">
            <el-input v-model="OwnerPo.age" placeholder="(可选)年龄只能是数字" onkeyup = "value=value.replace(/[^\d]/g,'')" maxlength="3" ></el-input>
          </el-form-item>
          <el-form-item label="手机">
            <el-input v-model="OwnerPo.link" placeholder="(必填)联系手机" onkeyup = "value=value.replace(/[^\d]/g,'')" maxlength="11" ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="10" style="float: right">
          <div class="select" >
            <input type="file" id="filed" hidden="" @change="filePreview" accept="image/jpeg">
            <img :src="OwnerPo.avatar" style="width: 220px;height: 170px;"/>
            <el-button type="text" @click="selectImg()" style="float: right">上传头像<i class="el-icon-upload el-icon--right"></i></el-button>
          </div>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="身份证">
            <el-input v-model="OwnerPo.idCard" placeholder="(必填)业主身份证" maxlength="18"></el-input>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="描述">
            <el-input type="textarea" v-model="OwnerPo.remark" placeholder="(选填)业主描述"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>

<script>
export default {
  name: "addOwner",
  props:['OwnerPo'],
  data() {
    return {
      src:'',
      textHide:true,
    }
  },
  methods: {
    selectImg:function(){
      document.getElementById('filed').click()
    },

    filePreview(e){
      let _this = this
      var files = e.target.files[0]
      if (!e || !window.FileReader) return  // 判断是否支持FileReader
      let reader = new FileReader()
      reader.readAsDataURL(files) // 文件转换
      reader.onloadend = function () {
        _this.OwnerPo.avatar = this.result
        _this.textHide=false;

      }
    }
  },
  created: function () {

  }

}
</script>

<style scoped>

</style>
